package com.huike.pmps.controller;

import com.huike.pmps.model.constants.GlobalConstants;
import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.Member;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.*;
import com.huike.pmps.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@RestController
@RequestMapping("/api/bases")
@Api(tags = "系统基础业务数据")
public class BasicDataController {
    @Autowired
    private ConsumerTokenServices consumerTokenServices;

    @Autowired
    DictionaryService dictionaryService;
    @Autowired
    ProvincesService provincesService;
    @Autowired
    CitiesService citiesService;
    @Autowired
    AreasService areasService;
    @Autowired
    MemberService memberService;
    @Autowired
    SupplierService supplierService;

    @ApiOperation(value = "省份数据", httpMethod = "GET")
    @GetMapping("/provinces")
    public Result selectProvinces() {
        return provincesService.selectAll();
    }

    @ApiOperation(value = "省份下的城市", httpMethod = "GET")
    @ApiImplicitParam(name = "provinceId", value = "省份ID", paramType = "query", dataType = "String")
    @GetMapping("/cities")
    public Result selectCitiesByProvinceId(String provinceId) {
        return citiesService.selectByCondition(provinceId);
    }

    @ApiOperation(value = "城市下的区域", httpMethod = "GET")
    @ApiImplicitParam(name = "cityId", value = "城市ID", paramType = "query", dataType = "String")
    @GetMapping("/areas")
    public Result selectAreasBy(String cityId) {
        return areasService.selectByCondition(cityId);
    }


    @ApiOperation(value = "产品类型", httpMethod = "GET")
    @GetMapping("/dict/product_type")
    public Result selectProductType() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_PRODUCT_TYPE);
    }

    @ApiOperation(value = "产品线", httpMethod = "GET")
    @GetMapping("/dict/product_line")
    public Result selectProductLine() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_PRODUCT_LINE);
    }

    @ApiOperation(value = "订单类型", httpMethod = "GET")
    @GetMapping("/dict/order_type")
    public Result selectOrderType() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_ORDER_TYPE);
    }

    @ApiOperation(value = "合同类型", httpMethod = "GET")
    @GetMapping("/dict/contract_type")
    public Result selectContractType() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_CONTRACT_TYPE);
    }

    @ApiOperation(value = "课程类型", httpMethod = "GET")
    @GetMapping("/dict/course_type")
    public Result selectCourseType() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_COURSE_TYPE);
    }


    @ApiOperation(value = "课程上线状态", httpMethod = "GET")
    @GetMapping("/dict/course_online_state")
    public Result selectCourseOnline() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_COURSE_ONLINE_TYPE);
    }

    @ApiOperation(value = "课程进度状态", httpMethod = "GET")
    @GetMapping("/dict/course_schedule")
    public Result selectCourseSchedule() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_COURSE_SCHEDULE_TYPE);
    }

    @ApiOperation(value = "课程前期沟通进度", httpMethod = "GET")
    @GetMapping("/dict/course_exchange")
    public Result selectCourseExchange() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_COURSE_EARLY_EXCHANGE_TYPE);
    }


    @ApiOperation(value = "服务类型(配音/租赁/化妆/...)", httpMethod = "GET")
    @GetMapping("/dict/supplier_service_content")
    public Result selectSupplierServiceContent() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_SUPPLIER_SERVICE_CONTENT_TYPE);
    }


    @ApiOperation(value = "学科门类", httpMethod = "GET")
    @GetMapping("/dict/subject_category")
    public Result selectSubjectCategory() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_SUBJECT_CATEGORY_TYPE);
    }

    @ApiOperation(value = "拍摄形式", httpMethod = "GET")
    @GetMapping("/dict/shoot_mode")
    public Result selectShootMode() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_SHOOT_MODE_TYPE);
    }

    @ApiOperation(value = "发票类型", httpMethod = "GET")
    @GetMapping("/dict/invoice_type")
    public Result selectInvoiceType() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_INVOICE_TYPE);
    }

    @ApiOperation(value = "支付状态", httpMethod = "GET")
    @GetMapping("/dict/payment_state")
    public Result selectPaymentState() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_PAYMENT_STATE_TYPE);
    }


    @ApiOperation(value = "课程编导", httpMethod = "GET")
    @GetMapping("/course_charge")
    public Result selectCourseCharge(HttpServletRequest request) {
        //从请求头中获取token
        Member member = (Member) request.getSession().getAttribute(TokenUtil.getToken(request));
        return memberService.selectCourseCharge(member);
    }

    @ApiOperation(value = "供应商类型", httpMethod = "GET")
    @GetMapping("/supplier_type")
    public Result selectBySupplierType() {
        return dictionaryService.selectByType(GlobalConstants.DICTIONARY_SUPPLIER_TYPE);
    }


    @ApiOperation(value = "供应商", httpMethod = "GET")
    @GetMapping("/suppliers/{supplierTypeId}")
    public Result selectSuppliers(@PathVariable("supplierTypeId") Integer supplierTypeId) {
        return supplierService.selectBySupplierType(supplierTypeId);
    }

    @ApiOperation(value = "单个供应商提供服务类型", httpMethod = "GET")
    @GetMapping("/suppliers/service_content/{supplierId}")
    public Result selectSupplierServiceContent(@PathVariable("supplierId") Integer supplierId) {
        return supplierService.selectSupplierServiceContent(supplierId);
    }

}
